package com.woniu.login.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.common.entity.AdmCustomer;
import com.woniu.common.entity.Result;
import com.woniu.login.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
public class CustomerController {
    @Autowired
    CustomerService customerService;
    //  查询所有客户
    @PostMapping("/getall/{pageIndex}/{pageSize}")
    public Result<IPage<AdmCustomer>> getAll(
            @PathVariable("pageIndex") int pageIndex,
            @PathVariable("pageSize") int pageSize,
            @RequestBody AdmCustomer admCustomer, HttpServletRequest request) {
        IPage<AdmCustomer> customerIPage = customerService.getAll(pageIndex, pageSize, admCustomer);
        return Result.ok(customerIPage);
    }
    //  添加客户
    @PostMapping("/add")
    public Result addCustomer(@RequestBody AdmCustomer admCustomer, HttpServletRequest request) {
        customerService.addCustomer(admCustomer);
        return Result.ok("添加成功");
    }
    //  大量删除客户
    @PostMapping("/deletebatch")
    public Result deletebatch(@RequestBody Integer[] ids,HttpServletRequest request) {
        System.out.println(request.getHeader("number"));
        customerService.deletebatch(ids);
        return Result.ok("删除成功");
    }
    //  删除客户
    @PostMapping("/delete/{id}")
    public Result deleteCustomer(@PathVariable("id") int id, HttpServletRequest request) {
        customerService.deleteCustomer(id);
        return Result.ok("删除成功");
    }
    //  修改客户
    @PostMapping("/update")
    public Result updateCustomer(@RequestBody AdmCustomer admCustomer, HttpServletRequest request) {
        customerService.updateCustomer(admCustomer);
        return Result.ok("修改成功");
    }
    //  根据ID客户
    @PostMapping("/findById")
    public Result getCustomerById(HttpServletRequest request) {
        int userid = Integer.parseInt(request.getHeader("userid"));
        customerService.getCustomerById(userid);
        return Result.ok("修改成功");
    }

}
